package com.baizhi.service;

import com.baizhi.dao.EmpDao;
import com.baizhi.entity.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmpServiceImpl implements EmpService{

    @Autowired
    private EmpDao empDao;

    @Override
    public int delete(Integer id) {
        Emp empDB = empDao.findById(id);
        if(empDB==null) throw new RuntimeException("该员工信息不存在~~");
        return empDao.delete(id);
    }

    @Override
    public Emp findOne(Integer id) {
        return empDao.findById(id);
    }

    @Override
    public int save(Emp emp) {
        int i=0;
        if(emp.getId()==null){
            i=empDao.save(emp);
        }else {
            i=empDao.update(emp);
        }

        return i;
    }

    @Override
    public List<Emp> findAll() {
        return empDao.findAll();
    }
}
